# -*- encoding=utf-8 -*-
"""
python的单例模式__new__()在__init__()之前被调用，用于生产实例对象。
利用这个方法和类的属性的特点可以实现设计模式的单例模式。
单例模式是指创建唯一对象，单例模式设计的类只能实例化一个对象。
全局变量类
lst
"""
from functools import wraps


def singleton(cls):
    _instances = {}

    @wraps(cls)
    def get_instance(*args, **kwargs):
        if cls not in _instances:
            _instances[cls] = cls(*args, **kwargs)
        return _instances[cls]

    return get_instance


@singleton
class GlobalManager:

    def __init__(self):
        print("GlobalManager __init__")
        self.current_nb_index = 0
        self.dp_info_dic = {}
        self.knc_name_dic = {}
        self.qnc_name_dic = {}
        self.md_name_dic = {}
        # 0 对应第一页签 ip
        self.index_ip_list = []
        self.nc_name_list = []
        self.manager_ip = []
        # 千兆2个万兆2个 万兆2个 [0,1,2,3,4,5]
        '''
        界面
        0  2  4
        1  3  5
        '''
        self.device_uuid_tab0 = {}
        self.device_uuid_tab1 = {}
        self.device_uuid_tab2 = {}
        self.device_uuid_tab3 = {}
        self.device_uuid_tab4 = {}
        self.device_uuid_tab5 = {}
        self.device_uuid = {}
        # 网卡名称
        self.jhnc_list = []
        self.jsnc_list = []
        self.ccnc_list = []

    def set_current_nb_index(self, index):
        self.current_nb_index = index

    def get_current_nb_index(self):
        return self.current_nb_index

    def set_dic_to_dic(self, tp, temp_dic):
        if tp == 1:
            self.dp_info_dic = dict(temp_dic)
        elif tp == 2:
            self.knc_name_dic = dict(temp_dic)
        elif tp == 3:
            self.qnc_name_dic = dict(temp_dic)
        elif tp == 4:
            self.md_name_dic = dict(temp_dic)
        elif tp == 5:
            self.device_uuid_tab0 = dict(temp_dic)
        elif tp == 6:
            self.device_uuid_tab1 = dict(temp_dic)
        elif tp == 7:
            self.device_uuid_tab2 = dict(temp_dic)
        elif tp == 8:
            self.device_uuid_tab3 = dict(temp_dic)
        elif tp == 9:
            self.device_uuid_tab4 = dict(temp_dic)
        elif tp == 10:
            self.device_uuid_tab5 = dict(temp_dic)
        else:
            pass

    def get_dic_from_type(self, tp):
        if tp == 1:
            return self.dp_info_dic
        elif tp == 2:
            return self.knc_name_dic
        elif tp == 3:
            return self.qnc_name_dic
        elif tp == 4:
            return self.md_name_dic
        elif tp == 5:
            return self.device_uuid_tab0
        elif tp == 6:
            return self.device_uuid_tab1
        elif tp == 7:
            return self.device_uuid_tab2
        elif tp == 8:
            return self.device_uuid_tab3
        elif tp == 9:
            return self.device_uuid_tab4
        elif tp == 10:
            return self.device_uuid_tab5
        else:
            return {}

    def set_list_to_list(self, tp, temp_list):
        if tp == 1:
            self.index_ip_list = list(temp_list)
        elif tp == 2:
            self.nc_name_list = list(temp_list)
        else:
            pass

    def get_lsit_from_type(self, tp):
        if tp == 1:
            return self.index_ip_list
        elif tp == 2:
            return self.nc_name_list
        else:
            return []


if __name__ == '__main__':
    pass
